<?php
	class RegisterHandler{
		
		private $m_db = null;
		private $validate = null;
		// Kontruktorn till klassen där vi matar in en databas.
		public function __construct(Database $db) {
			$this->m_db =$db;
			
			$this->validate = new Validator();
		}
		
		
		// Kollar om namnet redan finns i databasen
		public function DoExists($name)
		{
			$sqlQuery = "SELECT name FROM login WHERE name = ?";
			
			$stmt = $this->m_db->Prepare($sqlQuery);
			
			$stmt->bind_param('s', $name);
			
			if($this->m_db->execute($stmt) > 0)
			{
				return true;
			}
			return false;
			
		}
		public function DeletePerson($name)
		{
			$sqlQuery = "DELETE FROM login WHERE name = ?";
			
			$stmt = $this->m_db->Prepare($sqlQuery);
			
			$stmt->bind_param('s', $name);
			
			$this->m_db->execute($stmt);


		}
		public function DoRegister($name, $pass){
			$sqlQuery = "INSERT INTO login(name,pass) VALUES(?, ?)";
			
			$stmt = $this->m_db->Prepare($sqlQuery);
			
			$stmt->bind_param('ss', $name, $pass);
			
			if($this->m_db->execute($stmt) === 0)
			{
				return true;
			}
			return false;
		}


		// Kollar om namn är tom
		public function nameIsEmpty($name){
			if(empty($name)){
				return true;
			}
			return false;
		}
		// Kollar om lösen är tomt
		public function passIsEmpty($pass){
			if(empty($pass)){
				return true;
			}
			return false;
		}
		public function validatePass($pass){
			if($this->validate->validatePassword($pass)){
				return true;
			}
			return false;
		}

	}
?>